<style src="./index.scss" lang="scss" scoped rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
import apiConfig from "./../apiConfig";
export default {
    props: {
        // 使用者window实例 必定义
        appWindow: {
            type: Object,
            default: null,
        },
        // 接口列表
        apiConfig: {
            type: Object,
            default: apiConfig,
        },
        value: {
            type: String,
            default: "",
        },
        level: {
            type: String,
            default: "street",
        },
        clean: {
            type: Boolean,
            default: false,
        },
        disabled: {
            type: Boolean,
            default: false,
        },
    },

    computed: {
        levelNum() {
            let _num = 0;
            if (this.level == "street") {
                _num = 4;
            } else if (this.level == "region") {
                _num = 3;
            } else if (this.level == "city") {
                _num = 2;
            } else if (this.level == "province") {
                _num = 1;
            }
            return _num;
        },
    },
    data() {
        return {};
    },
    methods: {
        clean() {
            if (this.levelNum > 0) {
                this.value.province = "";
                this.value.provinceCode = "";
            }
            if (this.levelNum > 1) {
                this.value.city = "";
                this.value.cityCode = "";
            }
            if (this.levelNum > 2) {
                this.value.region = "";
                this.value.regionCode = "";
            }
            if (this.levelNum > 3) {
                this.value.street = "";
                this.value.streetCode = "";
            }
            this.$emit("input", this.value);
            this.$emit("change", this.value);
        },
        selectAddress() {
            if(this.disabled){
                return 
            }
            this.$vFN.Directives.SelectAddress({
                appWindow: this.appWindow,
                selected: this.value,
                level: this.level,
                apiConfig: this.apiConfig,
                onSuccess: (res) => {
                    this.$emit("input", res.data);
                    this.$emit("change", res.data);
                },
            });
        },
    },
    watch: {},
    mounted() {},
    beforeCreate() {},
};
</script>